package com.ruan.controller;


import com.ruan.entity.Address;
import com.ruan.entity.R;
import com.ruan.requestdata.AddressRequestData;
import com.ruan.service.AddressService;
import com.ruan.vo.AddressVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ClassName:AddressController
 * @Author:阮昇
 * @Description:
 * @Datetime: 2023/9/13 20:17
 **/
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    @PostMapping("/addAddress")
    @PreAuthorize("hasAuthority('addAddress')")
    public R<Void> addAddress(AddressRequestData addressRequestData){
        return addressService.addAddress(addressRequestData);
    }

    @RequestMapping("/getAddressByUserId")
    @PreAuthorize("hasAuthority('getAddressByUserId')")
    public R<List<AddressVo>> getAddressByUserId(String userId){
        return addressService.getAddressByUserId(userId);
    }


    @RequestMapping("/getAddressById")
    @PreAuthorize("hasAuthority('getAddressById')")
    public R<Address> getAddressById(Integer id){
        return addressService.getAddressById(id);
    }

    @PostMapping("/editAddress")
    @PreAuthorize("hasAuthority('editAddress')")
    public R<Void> editAddress(AddressRequestData addressRequestData){
        return addressService.editAddress(addressRequestData);
    }

    @RequestMapping("/deleteAddress")
    @PreAuthorize("hasAuthority('deleteAddress')")
    public R<Void> deleteAddress(Integer id,String userId){
        return addressService.deleteAddress(id,userId);
    }
}
